﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using He.Common;

namespace He.Web.user
{
    public partial class pwd_edit : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
                return;
            }

            if (!IsPostBack)
            {
                lblUserName.Text = User.Identity.Name;
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            He.BLL.member mgr = new He.BLL.member();
            string username = User.Identity.Name;
            if (mgr.Exists(username))
            {
                He.Model.member member = mgr.GetModel(username);
                string rawPwd = CryptoHelper.DESEncrypt(txtRawPwd.Text.Trim());
                if (member.user_pwd == rawPwd)   //旧密码正确
                {
                    member.user_pwd = CryptoHelper.DESEncrypt(txtNewPwd.Text.Trim());
                    mgr.Update(member);
                    lblMsg.Text = "密码修改成功！";
                    return;
                }
                else
                {
                    lblMsg.Text = "旧密码错误，请重试!";
                    return;
                }
            }
            else
            {
                Response.Redirect("~/error.aspx?s=用户不存在");
            }
        }
    }
}